package com.jingyanzi.member.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.jingyanzi.member.domain.TagDO;
import com.jingyanzi.member.domain.result.ResultDO;
import com.jingyanzi.member.request.SingleRequest;
import com.jingyanzi.member.response.PageResponse;
import com.jingyanzi.member.response.SingleResponse;
import com.jingyanzi.member.service.ITagService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@Api(value="客户tag标签",tags={"客户tag标签管理"})
@RestController
@RequestMapping("/tags")
public class TagsController {

	@Autowired
	private ITagService tagService;
	
	@ApiOperation(value = "添加客户标签",  notes="添加客户标签")
	@ApiImplicitParam(name = "request", value = "客户标签", required = true, dataType = "SingleRequest<TagDO>")
	@RequestMapping(value = "/add.json", method = RequestMethod.POST)
	public SingleResponse<TagDO> add(@RequestBody SingleRequest<TagDO> request) {
		
		TagDO tagDO = request.getData();
		ResultDO result = tagService.add(tagDO);
		SingleResponse<TagDO> response = new SingleResponse<TagDO>();
		if (result.isSuccess()) {
			response.setStatus(200);
			response.setVersion(1);
			response.setMsg("");
		} else {
			response.setStatus(500);
			response.setVersion(1);
			response.setMsg("");
		}

		return response;
	}

	@ApiOperation(value = "删除客户标签",  notes="删除客户标签")
	@ApiImplicitParam(name = "request", value = "客户标签", required = true, dataType = "SingleRequest<TagDO>")
	@RequestMapping(value = "/delete.json", method = RequestMethod.POST)
	public SingleResponse<TagDO> delete(@RequestBody SingleRequest<TagDO> request) {
		
		TagDO tagDO = request.getData();
		
		ResultDO result = tagService.remove(tagDO.getIds());
		SingleResponse<TagDO> response = new SingleResponse<TagDO>();
		if (result.isSuccess()) {
			response.setStatus(200);
			response.setVersion(1);
			response.setMsg("");
		} else {
			response.setStatus(500);
			response.setVersion(1);
			response.setMsg("");
		}

		return response;
	}

	@ApiOperation(value = "查询客户标签",  notes="查询客户标签")
	@ApiImplicitParam(name = "request", value = "客户id", required = true, dataType = "SingleRequest<TagDO>")
	@RequestMapping(value = "/list.json", method = RequestMethod.POST)
	public PageResponse<TagDO> list(@RequestBody SingleRequest<TagDO> request) {
		
		TagDO tagDO = request.getData();
		
		ResultDO result = tagService.list(tagDO.getCustomerId());
		PageResponse<TagDO> response = new PageResponse<TagDO>();
		if (result.isSuccess()) {
			response.setStatus(200);
			response.setVersion(1);
			response.setMsg("");
			response.setData((List<TagDO>) result.getModel(ResultDO.FIRST_MODEL_KEY));
		} else {
			response.setStatus(500);
			response.setVersion(1);
			response.setMsg("");
		}
		
		return response;
	}
}
